package networks;

import networks.client.NetWorkState;
import networks.client.SocketClient;
import networks.event.Delegate;
import networks.manager.NetworkManager;
import networks.manager.Routes;
import networks.protocol.Message;

public class App {
    public static void main(String[] args) throws Exception {
        System.out.println("Hello, World!");

        SocketClient _client = new SocketClient();
        _client.NetWorkStateChangedEvent = new Delegate.ActionOne<NetWorkState>() {
            @Override
            public void Invoke(NetWorkState state) {
                System.out.println("Gate NetWorkStateChangedEvent: " + state);
            }
        };

        NetworkManager.Instance().Start();

        _client.InitClient("192.168.10.254", 4001, new Delegate.Action() {
            @Override
            public void Invoke() {
                _client.Connect(new Delegate.Action() {
                    @Override
                    public void Invoke() {
                        protobuf.gate_msg.Gate.c2s_connect.Builder msg = protobuf.gate_msg.Gate.c2s_connect
                                .newBuilder();
                        msg.setUsername("fifthking");
                        _client.Request(Routes.C2S_GATE_CONNECT, msg.build(), new Delegate.ActionOne<Message>() {
                            @Override
                            public void Invoke(Message o) {
                                byte[] data = o.Decode();
                                protobuf.gate_msg.Gate.s2c_connect s2c = null;
                                try {
                                    s2c = protobuf.gate_msg.Gate.s2c_connect.parseFrom(data);
                                    System.out.println("s2c_connect : " + s2c);
                                } catch (com.google.protobuf.InvalidProtocolBufferException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    }
                });
            }
        });
    }
}
